﻿using Coldairarrow.Business.BackStage.ConsumeChats;
using Coldairarrow.IBusiness.BTB_StaffUsers;
using Coldairarrow.Util;
using Coldairarrow.Util.DTO.OnlineChat;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.BackStage.InstantMessag
{
    [Route("/BackStage/[controller]/[action]")]
    public class InstantMessagBackController : BaseApiController
    {
        readonly ICServiceOnlineChatBusiness _cuserOnlineChatBusiness;
        readonly IChatRoomBusiness _chatRoomBusiness;
        public InstantMessagBackController(ICServiceOnlineChatBusiness userOnlineChatBusiness, IChatRoomBusiness chatRoomBusiness)
        {
            _cuserOnlineChatBusiness = userOnlineChatBusiness;
            _chatRoomBusiness = chatRoomBusiness;
        }

        /// <summary>
        /// 后台 —— 刷新客服未读消息数量
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task GetCServiceUnReadCountMessage0([FromBody] ClassIdDTO input)
        {
            await _cuserOnlineChatBusiness.UserGetUnReadCountAsync(input);
        }

        /// <summary>
        /// 后台——发送未读订单消息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task SendUnReadNewOrderCount(SendOrderCountDTO input)
        {
            await _cuserOnlineChatBusiness.GetUserNewOrderCountAsync(input.UserIds,input.OrderCount,input.CheckStr);
        }


        /// <summary>
        /// 后台——刷新客服用户列表
        /// </summary>
        [HttpPost]
        public async Task GetRoomList1([FromBody] ClassIdDTO input)
        {
            await _cuserOnlineChatBusiness.UpdateRoomListAsync(input.ClassId);
        }

        /// <summary>
        /// 前台 —— 获取客服聊天历史记录（分页）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ChatLogListDTO> GetCServiceMassageLog0([FromBody] GetMassageDTO input)
        {
            return await _cuserOnlineChatBusiness.GetCServiceMessageLogAsync(input);
        }

        /// <summary>
        /// 后台 —— 客服发送聊天消息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SendMessages1(UserSendChatDTO input)
        {
            await _cuserOnlineChatBusiness.CServiceSendMessageAsync(input);
        }

        /// <summary>
        /// 前台——从消息列表移除用户(下次会给用户随机分配客服)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task CustomRemove(IdInputDTO input)
        {
            await _cuserOnlineChatBusiness.DelRoomAsync(input.Id);
        }

        /// <summary>
        /// 客服获取房间用户信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<object> GetRoomUserInfo(IdInputDTO input)
        {
            return await _cuserOnlineChatBusiness.GetRoomUserInfoAsync(input);
        }

        /// <summary>
        /// 后台——获取首页聊天统计数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<object> GetUserChatSumData()
        {
            return _chatRoomBusiness.GetUserLogSumDTO();
        }

    }
}
